// packageJ/service_station_dividend/service_station_dividend.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    settled: "",
    unsettled: "",
    language:"",
    member:{},

    list: [],
    page: 1,
    total_page: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData();
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en });
  },
  onChange(e){
    this.setData({active:e.detail.index});
    this.getData();
  },

  getData(page = 1) {
    let json = { page };
    if (this.data.active !== 0) {
      if (this.data.active == 1) {
        json.type = 'unsettled';
      } else {
        json.type = 'settled';
      }
    }
    let urlStr = app.getNetAddresss("plugin.unicom-server-station.frontend.settlement.index");
    app._getNetWork({
      url:urlStr,
      data:json,
      success:resdata=>{
        let {result,data,msg} = resdata.data;
        if (result) {
          this.setData({
            page : data.settlements.current_page,
            total_page : data.settlements.last_page,
            member : data.member,
            settled : data.settled,
            unsettled : data.unsettled,
          })
          wx.setNavigationBarTitle({
            title:data.plugin_name,
          })
          if(page==1){
            this.setData({list:data.settlements.data})
          }else{
            let list  =  this.data.list.concat(data.settlements.datata)
            this.setData({list})
          }
        } else {
          app.tips(msg);
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    let page = this.data.page + 1;
    this.getData(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})